<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>查看购物车</title>
<link rel="stylesheet" type="text/css" href="./Public/Home/css/viewShopCart.css"/>
<script type="text/javascript" src="./Public/uploadify/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="./Public/Home/js/style.js"></script>
<script type="text/javascript">
$(function(){
	//购买商品数量		
	$(".increase").click(function(){
		var n = $(this).prev().val();
		var num = parseInt(n)+1;
		if(num == 0){ return;}
		$(this).prev().val(num);	
	})
	$(".decrease").click(function(){
		var n = $(this).next().val();
		var num = parseInt(n)-1;
		if(num == 0){alert('最少购买一件商品哦');return;}
		$(this).next().val(num);

	});	
})
</script>
</head>
<body>
<header>
<!--顶层-->
	<div class="header_top">
		<div class="header_c">
			<?php if(isset($_SESSION['user'])) :?>
				<span>
				欢迎您，
				<a href="<?php echo U('Individual/index',['cid'=>$_GET['cid']])?>"><?php echo $user['account']?></a>！
				<a href="<?php echo U('Member/out')?>">[退出]</a>
				</span>
			<?php else :?>
				<span>
				<a href="<?php echo U('Member/index')?>">欢迎登录名鞋库</a>&nbsp;
				<a href="<?php echo U('Member/register')?>">免费注册</a>	
				</span>
			<?php endif ?>

			<ul class="h_menu">
				<!--<li class="li_left">
					<a href="">我的订单</a>					
				</li>-->
				<li class="li_left_w">
					<?php if(isset($_SESSION['user'])) :?>
					<p><a href="<?php echo U('Individual/index',['cid'=>$_GET['cid']])?>">我的名鞋库</a></p>
					<?php else :?>
					<p><a href="<?php echo U('Member/index')?>">我的名鞋库</a></p>	
					<?php endif ?>	
					<!--<div class="show_hide">
						<a href="">我的订单</a>
						<a href="">密码管理</a>
					</div>-->
				</li>							
			</ul>
		</div>
	</div>
	<div class="warp">
		<div class="logo"></div>
	</div>
</header>	

<!--show car-->
<nav id="box">
	<div class="wrap"></div>
	<div class="car_body">
		<div class="cart_tit">我的购物车</div>
		<div class="cart_tb_head">			
			<table border="0" cellspacing="0" cellpadding="0">
				<tbody>
					<tr>
						<th style="width:398px">商品信息</th>
						<th style="width: 110px">赠送积分</th>
						<th style="width: 110px">销售价格</th>
						<th style="width: 100px">数量</th>
						<!--<th style="width: 90px">折扣/优惠</th>-->
						<th style="width: 110px">小计</th>
						<th style="width: 110px">操作</th>
					</tr>
				</tbody>	
			</table>
		</div>		
		<table class="goods_car" border="0" cellspacing="0" cellpadding="0">
			<tbody>
				<tr >
					<th style="width:398px"></th>
					<th style="width: 110px"></th>
					<th style="width: 110px"></th>
					<th style="width: 110px"></th>
					<th style="width: 110px"></th>
					<th style="width: 110px"></th>
					<!--<th style="width: 10px"></th>-->
				</tr>
				<?php if(isset($goodsCarData)) :?>				
				<?php foreach ($goodsCarData as $k=>$v){?>
				<tr>
					<td>
						<a class="goods_pic" href="<?php echo U('Product/index',['cid'=>$v['cid'],'gid'=>$v['id']])?>">
							<img src="<?php echo $v['picture']?>"/>
						</a>								
						<a class="goods_cont" href="<?php echo U('Product/index',['cid'=>$v['cid'],'gid'=>$v['id']])?>">
							<?php echo $v['name']?>							
							<p>(
								<?php foreach ($v['options'] as $kk=>$vv){?>
									<?php echo $kk?>:<?php echo $vv?>,
								<?php }?>
							)</p>							
						</a>															
					</td>
					<!--赠送积分-->
					<td>
						0
					</td>
					<!--销售价格-->
					<td class="money">
						￥<?php echo $v['price']?>
					</td>
					<!--数量-->
					<td>
						<span class="numbox">
							<span class="num decrease num<?php echo $k?>" ></span>
							<input class="input_num input_num<?php echo $k?>" readonly="readonly" type="text" value="<?php echo $v['num']?>"/>
							<span class="num increase num<?php echo $k?>"></span>
						</span>
					</td>
					<!--折扣/优惠-->
					<!--<td class="money">
						-￥60.00
					</td>-->
					<!--小计-->
					<td class="money money<?php echo $k?>">
						￥<?php echo $v['total']?>
					</td>
					<!--操作-->
					<td>
						<a class="fav" href="">收藏</a>
						<br />
						<a class="fav" href="javascript:if(confirm('确定删除吗？'))location.href='<?php echo U('ShopCar/del',['sid'=>$k,'cid'=>$v['cid']])?>'">删除</a>
					</td>				
				</tr>	
				<!--隐藏域，当前商品sid，便于异步抓取-->
				<input type="hidden" class="goodsSid<?php echo $k?>" value="<?php echo $k?>"/>
				<!--更改购买商品数量，发异步-->
				<script type="text/javascript">
					$(function(){
						//发异步
						$('.num<?php echo $k?>').click(function(){
							//抓取购买商品数量
							var goodsNum = $('.input_num<?php echo $k?>').val();
							//抓取当前商品
							var sid = $('.goodsSid<?php echo $k?>').val();	
							//发异步
							$.ajax({
								type:"post",
								url:"<?php echo U('ShopCar/editNum')?>",
						        data:{gn:goodsNum,sid:sid},	        
								dataType:'json',
								//服务器返回数据				
								success:function(phpData){
									console.log(phpData);																		
									//单个商品价格(保留两位小数)
									var goodsPrice = '';	
									goodsPrice += <?php echo $v['price']?>*phpData.num;	
									$('.money<?php echo $k?>').html(goodsPrice);	
									//总数量
									var TotalNums = '';	
									TotalNums += phpData.TotalNums;
									//总价格	
									var totalPrice = '';
									totalPrice += phpData.totalPrice;																											
									$('.TotalNums').html(TotalNums);																		
									$('.c_total').html(totalPrice);
								}						
							});		
						});	
					})
				</script>
				<?php }?>
				<?php endif ?>
			</tbody>					
		</table>
		<div class="row"></div>
	</div>
	
	<?php if($goodsCarData) :?>					
	<div class="cart_check_info">
		商品数量：
		<i class="TotalNums"><?php echo $goodsCarNum?></i>
		件
		<!--<span>享受的优惠：</span>
		后台数据-->
		<p> 
			商品总金额：
			<span class="c_total">			
				￥<?php echo $goodsCarPrice?>
			</span>
		</p>
	</div>
	<?php else :?>
	<div class="cart_empty">
		<i>
			<img src="./Public/Home/images/31430.png" alt="" />
		</i>
		您还没有挑选商品，
		<a href="<?php echo U('Index/index')?>">返回首页</a>。
	</div>
	<?php endif ?>
	<div class="cart_check_act">
		<div class="tip">
			<span>提示：</span>
			加入购物车的商品无法为您保证库存，请及时下单支付。
		</div>	
		<a class="cart_goBuy" <?php if(isset($cateCid)){?>
                 href="<?php echo U('List/index',['cid'=>$cateCid])?>" <?php }else{?> href="<?php echo U('Index/index')?>" 
               <?php }?>>
			<i></i>
			继续购物
		</a>
		<script type="text/javascript">
			$(function(){
				//检测购物车中是否商品
				$('#goBuy').click(function(){
					var goBuy = 1;
					$.ajax({
						type:"post",
						url:"<?php echo U('ShopCar/shop')?>",
						data:{g:goBuy},	        
						dataType:'json',
						//服务器返回数据				
						success:function(phpData){
							console.log(phpData);															
							if(phpData == 1){
								location.href="<?php echo U('FillInfo/index',['cid'=>$_GET['cid']])?>";
							}else{
								alert("对不起，您的购物车没有商品，请返回首页");	
								location.href="<?php echo U('Index/index')?>";					
							}																	
						}							
					});				
				});
			})
		</script>
			<input id="goBuy" type="submit" value="下单结算"/>
	</div>	
</nav>
<!--end show car-->


<!--载入公共模板-->


<footer>
	<div class="foot_row">
		<div class="row">
			<div class="row_one">
				<!--版权-->
				<p>Copyright © 2016-09</p>
			</div>
			<div class="row_one">
				<!--备案号-->
				<p>云ICP备00000000号</p>
			</div>
			<div class="row_one">
				<!--网站信息-->
				<p>名鞋库 All Rights Reserved. </p>
			</div>
			<div class="row_one">
				<!--经营许可证-->
				<p>经营许可证云YN-0000000  </p>
			</div>
		</div>
		
		<div class="link">			
			<div class="Foot6">
				友情链接：
				<ul class="Foot7">
					<!--链接为5个，要改注意该js-->
					<li><a class="Foot6_text"href="https://www.baidu.com/">百度</a></li>
					<li><a class="Foot6_text"href="http://www.jd.com/">京东</a></li>					
					<li><a class="Foot6_text"href="https://www.taobao.com//">淘宝</a></li>					
					<li><a class="Foot6_text"href="https://www.tianmao.com//">天猫</a></li>					
				</ul>		
			</div>			
		</div>
	</div>
</footer>
</body>
</html>
